import Vue from 'vue';
import Vuex from 'vuex';
import { getPicListData } from '@/api/web/sysPicSource';
import { getEvaluateListData } from '@/api/web/sysEvaluate';
import { getNewsListData, getNewsDetailData } from '@/api/web/sysNewsContents';
import { getJournalListData, getJournalDetailData } from '@/api/web/sysJournal';
Vue.use(Vuex)
const state = {}
const getters = {}
const actions = {
	//获取文章源数据
	async getNewsData({ commit }, data) {
		let result = await getNewsListData({ ...data, status: '1' }).then(res => res.data);
		if (result.code === '0') {
			return result;
		} else {
			Promise.reject(new Error('faile'));
		}
	},

	//获取图片源数据
	async getImageData({ commit }, data) {
		let result = await getPicListData({ ...data }).then(res => res.data);
		if (result.code === '0') {
			return result;
		} else {
			Promise.reject(new Error('faile'));
		}
	},

	//获取期刊源数据
	async getJournalData({ commit }, data) {
		let result = await getJournalListData({ ...data }).then(res => res.data);
		if (result.code === '0') {
			return result;
		} else {
			Promise.reject(new Error('faile'));
		}
	},

	//获取文章源数据详情
	async getNewsDetail({ commit }, id) {
		let result = await getNewsDetailData(id).then(res => res.data);
		if (result.code === '0') {
			return !result.data ? {} : result.data[0];
		} else {
			Promise.reject(new Error('faile'));
		}
	},

	//获取期刊源详情数据
	async getJournalDetail({ commit }, id) {
		let result = await getJournalDetailData(id).then(res => res.data);
		if (result.code === '0') {
			return !result.data ? {} : result.data[0];
		} else {
			Promise.reject(new Error('faile'));
		}
	},

	//获取评价列表数据
	async getCommentData({ commit }, data) {
		let result = await getEvaluateListData(data).then(res => res.data);
		if (result.code === '0') {
			return result;
		} else {
			Promise.reject(new Error('faile'));
		}
	}
}
const mutations = {}
export default { state, getters, actions, mutations }